from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from tortoise.contrib.fastapi import register_tortoise

from setting import settings
from .v1 import v1

app = FastAPI(
    title='可视化系统',
    version='1.0',
    description='面向汽车数据分析web应用的后台API接口服务'
)

app.include_router(v1)

app.add_middleware(
    CORSMiddleware,
    # allow_origins=settings.ORIGINS,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

register_tortoise(
    app,
    db_url=settings.MYSQL_DATABASE_URI,
    modules={"models": ["models"]},
    generate_schemas=True,
    add_exception_handlers=True,
)
